package com.example.bishe.web.b.controller;


import com.example.bishe.entity.Admin;
import com.example.bishe.service.AdminService;
import com.example.bishe.util.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LDH
 * @since 2023/05/04
 */
@RestController
@RequestMapping("/b/admin")
@Api(value = "商户后台", tags = {"管理员管理"})
public class AdminController {

    @Autowired
    private AdminService adminService;

    @ApiOperation("管理员登录")
    @PostMapping("/login")
    public RestResult<Admin> login(@RequestBody Admin admin){
        Admin admin1 = adminService.login(admin);
        if (admin1 == null)
            return RestResult.error_msg(null, "账号或密码错误", -1);
        return RestResult.get_success(admin1);
    }

    @ApiOperation("管理员注册")
    @PostMapping("/register")
    public RestResult<Admin> register(@RequestBody Admin admin){
        return RestResult.get_success(adminService.register(admin));
    }

    @ApiOperation("管理员编辑")
    @PutMapping("/update")
    public RestResult<Admin> update(@RequestBody Admin admin){
        return RestResult.get_success(adminService.update(admin));
    }


}
